app.controller('todayOrderContorller', ['$scope', 'ajax', 'Flash','$state','$filter','SERVER_URL',function ($scope, ajax,Flash,$state,$filter,SERVER_URL) {

    $scope.queryData={
        orderNo:'',
        ctime_tend:''
    }

    ajax.get({
            url: 'back/order/newPage',
            debug: true
        }).then(function (result) {
            $scope.totalSize=result.totalSize;
            $scope.data=result;
            $scope.date=new Date().toLocaleString( );
        })

    //查询
    function list(e){
        $scope.queryData.ctime_like=$filter('date')($scope.queryData.ctime_like,'yyyy-MM-dd')
            ajax.get({
                url: "back/order/newPage",
                data: {
                    orderNo:$scope.queryData.orderNo,
                    ctime_like:$scope.queryData.ctime_like,
                    currentPage: e
                }
            }).then(function (result) {
                $scope.totalSize=result.totalSize;
                $scope.data=result;
            });
    }
    $scope.doQuery = function(){
        list(1);
    }
    list(1);
    $scope.pageChanged = function(e){
        list(e);
    }



    //重置按钮
    $scope.reset=function(){
        $scope.queryData={};
    }
        // 预订单列表列表

        $scope.genernate = function () {
            ajax.get({
                url: '/back/purchaseOrder/genernate',
                debug: true
            }).then(function (result) {

                Flash.create('success', '生成成功', 'custom-class');
                $state.go('admin.linePreOrder',null,{
                    reload:true
                });
            })
        }


        //查询订单详情列表
        $scope.queryOrderDetail = function (orderId) {
            ajax.get({
                url: "/back/order/orderDetailList",
                data: {
                    orderId: orderId
                }
            }).then(function (result) {
                $scope.data.isShowDetail = true;
                $scope.orderDetailList = result;
            });
        }


        //支付完成
        $scope.paySuccess = function (id) {
            ajax.post({
                url: "back/order/finishPay",
                data:{
                    orderId: id
                }
            }).then(function (result) {
                $state.go('admin.linePreOrder', null, {
                    reload: true
                });
            });
        };

        //删除订单
        $scope.del = function(id){
            ajax.post({
                url: 'back/order/delete',
                data:{
                    orderId:id
                }
            }).then(function(){
                Flash.create('success', '删除成功', 'custom-class');
                $state.go('admin.linePreOrder',null,{
                    reload:true
                });
            })
        }
    //订单一键编号
    $scope.orderNumer=function(){
        ajax.get({
            url: 'back/order/todayOrderNo',
        }).then(function(){
            Flash.create('success', '编号成功', 'custom-class');
            $state.go('admin.todayOrder',null,{
                reload:true
            });
        })
    }
    //导出
    $scope.export=function(){

        angular.isUndefined($scope.queryData.ctime_like)?location.href=SERVER_URL+'/back/order/newPageExportExcel':location.href=SERVER_URL+'/back/order/newPageExportExcel?ctime_like='+$scope.queryData.ctime_like;
    }

}]);